package com.sf.sms.software.action;

import com.sf.sms.software.entity.Software;
import com.sf.sms.software.entity.dto.SoftwareDTO;
import com.sf.sms.software.service.SoftwareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 80002004 on 2016/8/30.
 */
@Controller
@RequestMapping("/softwarereview")
public class SofwareReviewAction {

    @Autowired
    SoftwareService softwareService;

    @ResponseBody
    @RequestMapping("/getreview")
    public Map<String, Object> getReview(Integer pageNum,Long categoryId) {
        Map<String, Object> map = new HashMap<String, Object>();
        Long total = 0l;
        List<SoftwareDTO> softwareList = new ArrayList<SoftwareDTO>();
        if ( categoryId == null ) {
            softwareList = softwareService.getReviewSoftware(pageNum);
            total = softwareService.getReviewSoftwareCount();
        } else {
            softwareList = softwareService.getReviewSoftwareByCategory(categoryId, pageNum);
            total = softwareService.getReviewSoftwareByCategoryCount(categoryId);
        }
        map.put("status","success");
        map.put("items",softwareList);
        map.put("total", total);
        return map;
    }

}
